
/*
*Released on 28th June 2008.
*Any violations can be reported at paritosh@wikiocean.net
*What is treated as violations can be found at www.wikiocean.net/ppl1-voilations*
******************************************************************************
* The contents of this file are subject to POOL Public License 1.0 and later.
* POOL Public License is based on Affero GPL v3 and additional conditions.
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the Affero GPL v3 License at http://www.gnu.org/licenses/agpl.html
* You may obtain a copy of the POOL Public License 1.0 or later at www.wikiocean.net/license/ppl.html
* Software distributed under POOL Public License 1.0 is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Initial Developer of the Original Code is Paritosh Pungaliya (C) 2008. All Rights Reserved.
******************************************************************************
* Objective of the additional terms (license)
* 1) Is to extend the software freedom to freedom to work.
* 2) To ensure that knowledge is free from monopoly of agencies.
* 3) To avoid a situation where big corporate or investor can buy out free software groups and companies and then start milking the communities built around it.
* (this trend can be seen how the freedom is curtailed in companies that get Venture Capital funding.)
******************************************************************************
*/

package  query.report;

import java.sql.ResultSet;
import java.util.Hashtable;
import java.util.Vector;

import logger.PoolLogger;

import database.RecordSearch;
import dbmanager.Column;
import dbmanager.DBManager;
import dbmanager.GetIdName;

/**
 * <pre>
 * AutoUpdate Report is nothing but the report which is used for automatic updation in the existing report.
 * It will be always executed after completion of request. 
 * It will check the condition if it matches then modification within the report will be done with respect to the Request.
 * </pre>
 * @author mahendra
 *
 */
public class Autoupdate implements ReportInterface
{
	String buffer[];
	String Object;
	String process;
	String ReportName;
	String value;
	String key;
	String YES="yes";
	GetIdName  gid;
	Hashtable<Object, Object> Reportmap = new Hashtable<Object, Object>(); 
	String UPDATE="update";
	PoolLogger pl;
	
	public Autoupdate() {
		// logger
		pl = (PoolLogger) PoolLogger.getLogger(this.getClass().getName());
	}
	
	/**
	 * getbuffer method retrun buffer
	 * @return buffer:String array
	 */
	public String[] getBuffer() 
	{
		return buffer;
	}

	public String getReportName() 
	{
		return ReportName;
	}

	public void getResult() 
	{
		
	}
	/**
	 * setbuffer method set buffer variable
	 * @param buffer:String array 
	 */
	public void setBuffer(String[] buffer) 
	{
		this.buffer = buffer;
	}
	/**
	 * setDbmanager set DbManager object 
	 * @param database :DbMangaer Object
	 */
	public void initPool() 
	{
		gid  = new GetIdName();
		UPDATE = gid.getId(UPDATE);
	}
	/**
	 * this method set Autoupdate bject
	 */
	public void setObject(String Object) 
	{
		this.Object = Object;	
	}
	 /**
	  * this method set process 
	  * @param process:String  
	  */
	public void setProcess(String process) 
	{
		this.process = process;
	}
	/**
	 * this method set report name
	 * @param report name:String
	 */
	public void setReportName(String ReportName) 
	{
		this.ReportName = ReportName;
	}

	public void setValue(String value) 
	{
		this.value = value;
	}

	public void addReport()
	{	
		try 
		{
			ResultSet rs = DBManager.getSelect("Select * from "+ ReportName);		
			if(!rs.next())
				process = "mod";
		} 
		catch (Exception e) 
		{
			e.printStackTrace();			
			process ="mod";
			
		}
		
	}

	public void updateReport() 
	{
		
	}
	/**
	 * getkey method return key
	 * @return key :String
	 */
	public String getKey() 
	{
		return key;
	}
	/**
	 * setkey method set key
	 * @param key:String
	 */
	public void setKey(String key) 
	{
		this.key = key;
	}

	/**
	 * initilizedata method check report is update property 
	 */
	public void initializeData() 
	{
		if(YES.equals("no$"))
			YES="yes";
		RecordSearch sr = new RecordSearch();
		Hashtable<Object, Object >  temptable = new Hashtable<Object, Object>();
		temptable.put("mid", Object);
		temptable.put("pid", UPDATE);
		sr.setConditionMap(temptable);
		String result[] = sr.getArrayFromResultSet();
		for(int i=0;i<result.length;i++)
		{
			String splitresult[] = result[i].split("\t");
			String value=splitresult[Column.pv_index-1];
			if(value.equals("0"))
				value = splitresult[Column.vt_index-1];
			else
				value = gid.getItem(value);
			if(!value.equalsIgnoreCase(YES))
			{
				Reportmap.clear();
			}
		}	
	}

	public Hashtable<java.lang.Object, java.lang.Object> getReportMap() 
	{
		return Reportmap;
	}

	public void setReportmap(Hashtable<java.lang.Object, java.lang.Object> table) 
	{
		this.Reportmap = table;
	}

	public String gettypeofreport()
	{
		return "autoupdate";
	}

	public void settypeofreport(String typeofreport) 
	{
	}

	public void setscheduleObject(String object) 
	{
		
	}

	public void setrepoton(String reporton) 
	{
		
	}
	public String getProcess() 
	{	
		return process;
	}

	
	public void setConditionmap(Vector<Object> table) {
		
	}	
}